package com.example.c94s3plyspringboot.web;

import org.springframework.web.bind.annotation.*;

@RestController
// page 会成为所有方法路径的前缀(路径)
@RequestMapping("page")
public class 地址映射 {

    /**
     * http://127.0.0.1/page/test1
     * @return
     */
    @RequestMapping("test1")
    public String test1(){
        return "test1111111================";
    }

    /**
     * http://127.0.0.1/page/test2
     * http://127.0.0.1/page/test2.do
     * @return
     */
    @RequestMapping(path={"test2","test2.do"})
    public String test2(){
        return "test2";
    }

    @RequestMapping(path={"test3"}, method = RequestMethod.GET)
    public String test3(){
        return "test3";
    }

    @GetMapping("test3.do")
    public String test3_1(){
        return "test3.do";
    }

    @PostMapping("test3.post")
    public String test3_2(){
        return "test3.post";
    }

    /**
     * 正确: http://127.0.0.1/page/test4.do1?a=xxx
     * 正确: http://127.0.0.1/page/test4.do1
     * 出现 a 参数访问该方法
     */
    @GetMapping(path="test4.do1", params = "a")
    public String test4(){
        return "test4.do1";
    }

    /**
     * 正确: http://127.0.0.1/page/test4.do1
     * 错误: http://127.0.0.1/page/test4.do1?a=xxx
     * 不出现 a 参数访问该方法
     */
    @GetMapping(path="test4.do2", params = "!a")
    public String test4_1(){
        return "test4.do2";
    }

    /**
     * 正确: http://127.0.0.1/page/test4.do3?b=100
     * 错误: http://127.0.0.1/page/test4.do3?b=200
     * 出现 b=100 参数访问该方法
     */
    @GetMapping(path="test4.do3", params = "b=100")
    public String test4_2(){
        return "test4.do3";
    }

    /**
     * 自行验证
     * 出现 a 参数访问该方法
     */
    @GetMapping(path="test4.do4", params = "b!=100")
    public String test4_3(){
        return "test4.do4";
    }

    /**
     * 请求头域参数限制
     * @return
     */
    @GetMapping(path="test5",
            headers = {"Host=localhost","Accept-Language=zh-CN,zh;q=0.9"})
    public String test5(){
        return "test5";
    }

    /**
     * 请求头域中 Content-Type 参数限定
     */
    @PostMapping(path="test6",consumes = "application/x-www-form-urlencoded")
    public String test6(){
        return "test6";
    }

    /**
     * RequestMapping
     *  1. 设置请求地址
     *  2. 对请求数据进行限定: params, headers, consumes(Content-Type)
     *  3. produces 用于在响应头中加入 Context-Type 参数, 一般用于解决乱码问题
     */
    @PostMapping(path="test6.do", produces = "text/html;charset=ISO-8859-1")
    public String test6_1(String name){
        return "hello "+ name;
    }


}
